﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sync.Source;
using System.Text;
using System.Threading.Tasks;

namespace Sync.IRC.MessageFilter.Filters.Osu
{
    class RecentUser: FilterBase, IOsu
    {
        const string recentlyCommand = "?recently";

        UserHistory historyRecorder = null;

        public RecentUser(UserHistory history)
        {
            historyRecorder = history;
        }

        public override void onMsg(ref MessageBase msg)
        {
            string message = msg.message.RawText;
            if (message[0] != '?')
                return;
            if (message.StartsWith(recentlyCommand))
            {
                msg.cancel = true;
                if (historyRecorder==null)
                    return;
                Dictionary<string, int> recentUserCollection = new Dictionary<string, int>();
                StringBuilder sb = new StringBuilder();
                historyRecorder.GetHistoryList().ForEach((UserHistory.Record record) =>
                {
                    //可以提取历史对话，不过现在没啥卵用了
                    if (!recentUserCollection.ContainsKey(record.userName))
                    {
                        recentUserCollection[record.userName] = 0;
                        // id->userName ||
                        sb.Append(record.id).Append("->").Append(record.userName).Append(" || ");
                    }
                });

                CBaseDanmuku danmaku = new CBaseDanmuku();
                danmaku.danmuku = "最近交流的用户: " + message;
                Program.syncInstance.GetMessageFilter().RaiseMessage(typeof(IDanmaku), new DanmakuMessage(danmaku));
            }
        }
    }
}
